import React, { Component, PropTypes } from "react";
import { HashRouter, Route, Redirect, Switch } from "react-router-dom";
import routerData from "../configs/routerData";

export default class MyRoute extends Component {
  render() {
    return (
      <Switch>
        {routerData.map((item, index) => {
          const { component: Comp, children, path, exact, to } = item;
          if (Array.isArray(children)) {
            console.log("path", path);
            return (
              <Route
                path={path}
                key={`${path}-${index}`}
                render={(props) => <Comp {...props}></Comp>}
              />
            );
          }
          if (!Comp && to) {
            return (
              <Redirect
                key={`${path}-${index}`}
                from={path}
                component={Comp}
                exact={exact}
                to={to}
              ></Redirect>
            );
          }
          return (
            <Route
              path={path}
              key={`${path}-${index}`}
              component={Comp}
            ></Route>
          );
        })}
      </Switch>
    );
  }
}
